package com.mfl.controller.admin;

import com.mfl.common.PageResult;
import com.mfl.common.Result;
import com.mfl.pojo.dto.KYCourseBookDTO;
import com.mfl.pojo.dto.KYCourseBookPageQueryDTO;
import com.mfl.pojo.vo.KYCourseBookVO;
import com.mfl.service.KYCourseBookService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/cky/admin/courseBook")
@Slf4j
public class KYCourseBookController {

    @Autowired
    private KYCourseBookService kyCourseBookService;

    /**
     * 分页查询课程书籍
     * @return
     */
    @GetMapping("/page")
    public Result<PageResult> page(KYCourseBookPageQueryDTO kyCourseBookPageQueryDTO){
        log.info("分页查询课程书籍：{}", kyCourseBookPageQueryDTO);
        PageResult pageResult = kyCourseBookService.pageQuery(kyCourseBookPageQueryDTO);
        return Result.success("", pageResult);
    }

    /**
     * 添加课程书籍
     * @param kyCourseBookDTO
     * @return
     */
    @PostMapping("/insert")
    public Result insert(@RequestBody KYCourseBookDTO kyCourseBookDTO){
        log.info("添加课程书籍：{}", kyCourseBookDTO);
        kyCourseBookService.insert(kyCourseBookDTO);
        return Result.success("添加成功");
    }

    /**
     * 批量删除课程书籍
     * @param ids
     * @return
     */
    @DeleteMapping("/batchDelete")
    public Result batchDelete(@RequestParam List<Integer> ids){
        log.info("批量删除课程书籍：{}", ids);
        kyCourseBookService.batchDelete(ids);
        return Result.success("删除成功");
    }

    /**
     * 根据id查询课程书籍
     * @param id
     * @return
     */
    @GetMapping("/getCourseBookById")
    public Result<KYCourseBookVO> getCourseBookById(int id){
        log.info("根据id查询课程书籍：{}", id);
        KYCourseBookVO kyCourseBookVO = kyCourseBookService.getCourseBookById(id);
        return Result.success("", kyCourseBookVO);
    }

    /**
     * 修改课程书籍
     * @param kyCourseBookDTO
     * @return
     */
    @PutMapping("/update")
    public Result update(@RequestBody KYCourseBookDTO kyCourseBookDTO){
        log.info("修改课程书籍：{}", kyCourseBookDTO);
        kyCourseBookService.update(kyCourseBookDTO);
        return Result.success("修改成功");
    }
}
